/*
 * TarifaBuilderPaso1.java
 *
 * Created on 4 de junio de 2007, 11:13 AM
 */

package inc.jmc.cyberboard.ui.ventas;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import inc.jmc.cyberboard.Tarifa;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import inc.jmc.cyberboard.common.ImageLoader;
import inc.jmc.cyberboard.common.NumFormat;

/**
 *
 * @author  JOlguin01
 */
public class TarifaBuilderPaso2 extends javax.swing.JPanel {
    
    /** Creates new form TarifaBuilderPaso1 */
	TarifaBuilderFrm parent;
    public TarifaBuilderPaso2(TarifaBuilderFrm parent) {
        initComponents();
        this.relojLabel.setSize(new Dimension(200,188));
        this.parent=parent;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        nextButton = new javax.swing.JButton();
        backButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        relojLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setLayout(null);

        nextButton.setText(">>");
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });

        add(nextButton);
        nextButton.setBounds(220, 240, 49, 23);

        backButton.setText("<<");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        add(backButton);
        backButton.setBounds(120, 240, 49, 23);

        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel2.add(relojLabel, java.awt.BorderLayout.CENTER);

        add(jPanel2);
        jPanel2.setBounds(30, 40, 200, 188);

        cancelButton.setText("Cancelar");
        cancelButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        add(cancelButton);
        cancelButton.setBounds(20, 240, 73, 23);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Paso 2");
        add(jLabel1);
        jLabel1.setBounds(30, 10, 110, 15);

    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed

        parent.tarifaAux=new Tarifa();
        parent.getContentPane().remove(parent.paso2);
        parent.getContentPane().add(parent.getJPanel1(), java.awt.BorderLayout.CENTER);
        parent.updateUI();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
    	parent.getContentPane().remove(parent.paso2);
        parent.getContentPane().add(parent.paso1, java.awt.BorderLayout.CENTER);
        parent.updateUI();
    }//GEN-LAST:event_backButtonActionPerformed

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
    	    
            parent.getContentPane().remove(parent.paso2);
            parent.getContentPane().add(parent.paso3, java.awt.BorderLayout.CENTER);
            parent.updateUI();
    }//GEN-LAST:event_nextButtonActionPerformed
    
    public void dibujaReloj()
    {
    	int divisiones=parent.tarifaAux.getFraccionesHora();
//    	vamos a llamar nuestro reloj
        BufferedImage bi=new BufferedImage(relojLabel.getWidth(),relojLabel.getHeight(),BufferedImage.TYPE_INT_RGB);
        float cenx=(float)(relojLabel.getWidth()/2.0f);
        float ceny=(float)(relojLabel.getHeight()/2.0f);
        float r=(float)((relojLabel.getWidth()+relojLabel.getHeight())/4.0);
        float alfaIncrem=(float)(360.0/divisiones);
        //Ahora lo vamos a divir en los segmentos que nos indico el usuario
        Graphics2D graphics=(Graphics2D)bi.getGraphics();
        graphics.drawImage(ImageLoader.images[ImageLoader.CARATULA_RELOJ].getImage(),null,null);
        graphics.setColor(new Color(255,255,128));
        
        if(divisiones>1)
            for(int i=0;i<divisiones;++i)
            {
                float grados=(float)(alfaIncrem*(i+1)*Math.PI/180);
                System.out.println("que onda");
                float x2=cenx+(float)(r*Math.sin(grados));
                float y2=ceny-(float)(r*Math.cos(grados));
                graphics.drawLine((int)cenx,(int)ceny,(int)x2,(int)y2);
                System.out.println("pintando una linea");
            }
        
        graphics.dispose();
        relojLabel.setIcon(new ImageIcon(bi));
        System.out.println("dispose()");
        this.updateUI();
        System.out.println("ya terinamos de pintar las rayas");
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton nextButton;
    private javax.swing.JLabel relojLabel;
    // End of variables declaration//GEN-END:variables
    
}
